Skip to content

Conversation

@niaow
Copy link
Member

@niaow niaow commented Mar 26, 2020

This reduces the overhead of small allocations. Previously a pointer sized allocation would take up an entire block - leaving 3 pointer-widths of wasted space. Small allocations are now bundled together, and are treated as a single object for garbage-collection purposes. These could be tracked separately, but not without paying for space to store additional garbage collector metadata.

Most tests in testdata call smallAlloc at some point.

@niaow niaow requested a review from aykevl March 27, 2020 16:21
@aykevl
Copy link
Member

aykevl commented Apr 7, 2020

I am somewhat cautious with this change. The benefit here is not nearly as obvious as with code size decreases or correctness fixes. In fact, a quick test with tinygo build -o test.elf -size=short -target=microbit ./testdata/gc.go shows a code size increase of 160 bytes and a static RAM increase of 16 bytes:

   code    data     bss |   flash     ram
   2496       4    2276 |    2500    2280

   code    data     bss |   flash     ram
   2656       4    2292 |    2660    2296

Therefore, I think the improvement should be measured in a real-world piece of code (such as the mqtt code we've been using for testing so far). How much is heap usage reduced? Is that reduction worth the cost, especially for small systems with little RAM (that would potentially benefit the most)?

This reduces the overhead of small allocations.
Previously a pointer sized allocation would take up an entire block - leaving 3 pointer-widths of wasted space.
Small allocations are now bundled together, and are treated as a single object for garbage-collection purposes.
These could be tracked seperately, but not without paying for space to store additional garbage collector metadata.
@niaow
Copy link
Member Author

niaow commented Jun 23, 2020

I think this can be done more efficiently with #1181 if we decide we want this

@niaow niaow closed this Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants